package javabook.ch09;
class Account{
	private int total = 0;
	synchronized void deposit(int amount){
		total += amount;
	}
	int gettotal(){
		return total;
	}
}

class Customer extends Thread{
	Account account1;
	Customer(Account account){
		this.account1 = account;
	}
	public void run(){
		try{
			for (int i = 0; i<200; i++){
				System.out.println("������" + getName() + ": " + i +"��°" );
				account1.deposit(1000);
				sleep(2);
				if(account1.gettotal() >= 500000)
					break;
			}
		}catch(Exception e){
			System.out.println(e);
		}
	}
}

class TVContribution{
	public static void main(String[] args) {
		
		Account account = new Account();
		Customer customers[] = new Customer[5];
		for(int i=0; i<5; i++){
			customers[i] = new Customer(account);
			customers[i].start();
		}
		for (int i = 0; i<5; i++){
			try{
				customers[i].join();
			}
			catch (InterruptedException e) {
				e.printStackTrace();
			}
		} System.out.println
		("���� �Ѿ� : " + account.gettotal());
	}
	
}